package org.cying.main.util;

import org.cying.main.domain.Group;
import org.cying.main.domain.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * 学生服务方法库
 * @author Cying
 */
public class StudentUtils {

    public static List<Group> parseToGroup(List<Student> studentList) {
        List<Group> groupList = new ArrayList<>();
        studentList.forEach(item -> {
            int index = groupList.indexOf(new Group(item.getGroup(), null));
            if (index != -1) {
                Group group = groupList.get(index);
                group.getStudentList().add(item);
            } else {
                List<Student> list = new ArrayList<>();
                list.add(item);
                Group group = new Group(item.getGroup(), list);
                groupList.add(group);
            }
        });
        return groupList;
    }

}
